#include <iostream>
using std::cout;
using std::endl;
//多态的变种
class Base{
public:
    Base(){
        cout << "Base()" << endl;
    }

    virtual
        void print(){
            cout << "Base::print" << endl;
        }

    //隐含的this指针   Base * const this
    // Base * const this = &Derived;
    // this->print();
    // Base * const this = pbase2; 多态
    void fun1(){
        this->print();
    }

    //
    void fun2(){
        Base::print();
    }

};

class Derived
:public Base
{
public:
    Derived(){
        cout << "Derived()" << endl;
    }
    //虚函数
    void print(){
        cout << "Derived::print" << endl;
    }
};



void test(){
    Base base;
    Derived derived;
    base.fun1();//(1) 不满足多态
    base.fun2();//(2) 不满足多态

    derived.fun1();//(3) ok
    derived.fun2();//(4) 不满足多态

    cout << "============" << endl;

    Base * pbase = &base;
    pbase->fun1();//(5) 不满足多态,绑定的地址是基类的地址，查找虚表查找的也是基类的
    pbase->fun2();//(6) 不满足多态
    cout << "------------------" << endl;
    Base * pbase2 = &derived;
    pbase2->fun1();//(7) 满足多态 ok
    pbase2->fun2();//(8) 不满足多态
}
//成员函数经过编译器处理过后，会形成这种形式
//func1(Base * const this);  pbase2->func1()----------->func1(pbase2);
//形参和实参的结合  Base * const this = pbase2;
//基类的指针去指向了派生类对象的地址，

int main()
{
    test();
    return 0;
}

